

package ro.ase.catalog.security.dao.hibernate;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Expression;
import ro.ase.catalog.beans.AclSid;
import ro.ase.catalog.dao.hibernate.GenericDAOImpl;
import ro.ase.catalog.security.dao.IAclSidDAO;

import java.util.List;


public class AclSidDAOImpl extends GenericDAOImpl<AclSid, Long>  implements IAclSidDAO {

    /* (non-Javadoc)
     * @see IAclSidDAO#findBySid(java.lang.String, boolean)
     */
    @SuppressWarnings("unchecked")
    public AclSid findBySid(String sid, boolean principal) {
        DetachedCriteria criteria = DetachedCriteria.forClass(AclSid.class);
        criteria.add(Expression.eq("sid", sid))
                .add(Expression.eq("principal", principal));

        List<AclSid> list = getHibernateTemplate().findByCriteria(criteria);
        if (!list.isEmpty()) {
            return list.get(0);
        }
        return null;
    }    
}
